package work20241217;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author zdl
 * @date 2024/12/17
 */
class Person implements Comparable<Person>{
    private String name;
    private Integer age;

    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public Integer getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(Integer age) {
        this.age = age;
    }

    public String toString() {
        return "Person{name = " + name + ", age = " + age + "}";
    }

    @Override
    public int compareTo(Person o) {
        int res = this.age - o.age;
        if (res == 0){
          return  this.name.compareTo(o.name);
        }else {
            return res;
        }
    }
}
public class Demo {
    public static void main(String[] args) {
        Set<Person> set  = new TreeSet<>();
        set.add(new Person("a",16));
        set.add(new Person("c",15));
        set.add(new Person("f",13));
        set.add(new Person("b",13));
        set.add(new Person("e",11));
        System.out.println(set);
    }
}
